#!/bin/bash

set -e

if [[ -n "${RF_DEBUG}" ]]; then
    set -x
fi

function usage() {
    echo -n \
"Usage: $(basename "$0") SERVICE COMMAND[S]

Use docker-compose to run a command for a service, or drop into a console.
Example: ./scripts/console api-server \"./sbt\"
"
}

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
    if [ "${1:-}" = "--help" ]; then
        usage
    elif [ "${1:-}" = "sbt" ]; then
        docker-compose \
            run --rm sbt
    else
        docker-compose \
            run --rm --no-deps --service-ports \
            --entrypoint "/bin/bash -c" \
            "$1" "${@:2}"
    fi
fi
